// Test_for_sort.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"
#include "winbase.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int _tmain(/*int argc, _TCHAR* argv[]*/)
{
		char* inputName = "C:/Users/bobby-bonifacia/input.txt";
		char* ouputName = "C:/Users/bobby-bonifacia/ouput.txt";
		
		ofstream out;
		ifstream output_check;
		
		cout<<"1-a test: a) 9 nubmers in right file\n";
		
		out.open(inputName);
		
		if(!out.is_open())
		{
			cout<<"Can't open file\n";
			getchar();
			return -1;
		}
		
		
		out<<"12 13 15 16 14 17 19 19 40";
		
		out.close();
		//string Parametrs = (inputName + " " + ouputName);
		TCHAR* data = TEXT("C:/Users/bobby-bonifacia/input.txt C:/Users/bobby-bonifacia/output.txt");
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<"	Problems with running program sort.exe";
		}
		else
		{
			cout<<" Program run succesful.\n";	
			
			output_check.open(ouputName);
			if(output_check.is_open())
			{
				cout<<" Error open file! Test Failed!\n";
			}
			else
			{
				int long unsigned prev_n;
				int long unsigned n;
				output_check>>prev_n;
				for(;;)
				{
					if(!(output_check>>n)) break;
					if(n<prev_n)
					{
						cout<<" Test failed\n";
						break;
					}
					prev_n = n;
				}
				cout<<" Test succeded\n";
			}
			output_check.close();
			
		}
		getchar();
		cout<<"Test 1-b: 100 random int numbers in right file.\n";
		out.open(inputName);
		if(!out.is_open())
		{
			cout<<"	Can't open file\n";
			getchar();
			return -1;
		}
		srand ( time(NULL) );
		for(int i=0;i<1000;i++)
			out<<rand()<<" ";
		out<<rand();
		out.close();
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Program rur successfuly\n";
			output_check.open(ouputName);
			if(output_check.is_open())
			{
				cout<<" Error open file! Test Failed!\n";
			}
			else
			{
				int long unsigned prev_n;
				int long unsigned n;
				output_check>>prev_n;
				for(;;)
				{
					if(!(output_check>>n)) break;
					if(n<prev_n)
					{
						cout<<" Test failed\n";
						break;
					}
					prev_n = n;
				}
				cout<<" Test succeded\n";
			}
			output_check.close();
		
		}		
		getchar();
		cout<<"Test 2-a: file doesn't exist\n";
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				TEXT("ininin.txt arrr.txt"),
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the result of the program\n";
		}
		getchar();
		cout<<"Test 2-b: wrong access to file\n";
		HANDLE myHandle = CreateFile(TEXT("C:/Users/bobby-bonifacia/input.txt"),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_HIDDEN,NULL);
		CloseHandle(myHandle);
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}

		getchar();
		cout<<"Test 2-c: files with size more than 8 Gb\n";
		cout<<" Make file or use existing?\n";
		char answer;
		cin>>answer;
		if(answer=='T')
		{
		
			out.open(inputName);
			if(!out.is_open())
			{
				cout<<"	Can't open file\n";
				getchar();
				return -1;
			}
			for(int long unsigned i = 0; i< 1520000000;i++)
				out<<rand()<<" ";
			out<<rand();
			out.close();
			
		}
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}

		getchar();
		cout<<"Test 3-a: wrong symbols in file\n";
		out.open(inputName);
		out<<"123; =123; ";
		out.close();
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}
		getchar();
		cout<<"Test 3-b: big numbers in file\n";
		out.open(inputName);
		out<<"9000000000 60000000000 30000000000 42142 123 3214 124 1241241241";
		out.close();
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}
		getchar();
		cout<<"Test 3-c: empty file\n";
		out.open(inputName);
		out.close();
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}
		getchar();
		cout<<"Test 3-d: more than one space\n";
		out.open(inputName);
		out<<"10 23   34  4 55 44";
		out.close();
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				data,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}
		getchar();
		cout<<"Test 4-a: no arguments\n";
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				NULL,
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}
		getchar();
		cout<<"Test 4-b: only one argument in command line\n";
		if(!ShellExecute(
				NULL,
				TEXT("open"),
				TEXT("Sort.exe"),
				TEXT("input.txt"),
				NULL,
				SW_SHOWNORMAL))
		{
			cout<<" Problems with running program sort.exe";
		}
		else
		{
			cout<<" Look at the program run\n";
		}
		cout<<"There's no more test!\n";
		getchar();
	return 0;
}

